import Pinyin from 'js-pinyin'
let imgUrl = 'https://ykzuishuai.oss-cn-hangzhou.aliyuncs.com/bike/'

function sortByFirstLetter(origin) {
	// 将目标数据进行排序
	origin = origin.sort((pre, next) => Pinyin.getFullChars(pre).localeCompare(Pinyin.getFullChars(next)))
	const newArr = []
	origin.map(item => {
		// 取首字母
		const key = Pinyin.getFullChars(item.name).charAt(0).toUpperCase()
		// console.log(key)
		const index = newArr.findIndex(subItem => subItem.letter === key)
		if (index < 0) {
			newArr.push({
				letter: key,
				data: [item]
			})
		} else {
			newArr[index].data.push(item)
		}
	})
	return newArr
}

export {
	sortByFirstLetter,
	imgUrl
}
